package com.dominator.api.service.impl;

import com.dominator.api.common.util.MyUtil;
import com.dominator.api.common.wrapper.Dto;
import com.dominator.api.mybatis.tuser.TUserEntity;
import com.dominator.api.mybatis.tuser.TUserMapper;
import com.dominator.api.service.DemoService;
import com.dominator.api.utils.api.Constants;
import com.dominator.api.utils.encode.Des3Utils;


import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.UUID;

@Service
public class DemoServiceImpl implements DemoService {

    @Autowired
    TUserMapper tUserMapper;


    @Autowired
    SqlSession sqlSession;



    @Override
    public Integer createUser(Dto dto) {
        TUserEntity tUserEntity=new TUserEntity().copyFrom(dto);
        tUserEntity.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        tUserEntity.setCreate_time(new Date());
        if (MyUtil.isNotEmpty(tUserEntity.getPassword())){
            tUserEntity.setPassword(Des3Utils.encode(tUserEntity.getPassword()));
        }
        tUserEntity.setIs_valid(Constants.is_valid.yes);
        return tUserMapper.insert(tUserEntity);


    }
}
